﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Entity;
using System.Web;
using System.Web.Mvc;
using HdipCricketClub.Models;
using HdipCricketClub.ViewModels;

namespace HdipCricketClub.ViewModels
{
    public class ScorecardEditDataViewModel
    {
        // properties

        public Fixture ScorecardFixture { get; set; }

        public ScorecardHeader ScorecardHeaderDetail { get; set; }

        public List<ClubFixturePlayer> ClubPlayers { get; set; }

        public ClubOtherFixtureDetail ClubOtherDetails { get; set; }

        public List<OpponentFixturePlayer> OpponentPlayers { get; set; }

        public OpponentOtherFixtureDetail OpponentOtherDetails { get; set; }

        public SelectList ClubBowlers_SelectList { get; set; }
             
        public SelectList ClubDismissalId_SelectList { get; set; }

        public SelectList OppDismissalId_SelectList { get; set; }

        public SelectList ClubBatsman_SelectList { get; set; }

        public SelectList ClubBowler_SelectList { get; set; }

        public SelectList OppBatsman_SelectList { get; set; }

        public SelectList OppBowler_SelectList { get; set; }

        //public string DismissalId_SelectedItem { get; set; }

        // database context

        CricketClubEntities db = new CricketClubEntities();

        // repositories
                
        FixtureRepository fixtureRepository = new FixtureRepository();
        ScorecardHeaderRepository scorecardHeaderRepository = new ScorecardHeaderRepository();
        ClubFixturePlayerRepository clubFixturePlayerRepository = new ClubFixturePlayerRepository();
        ClubOtherFixtureDetailRepository clubOtherFixtureDetailRepository = new ClubOtherFixtureDetailRepository();
        OpponentFixturePlayerRepository opponentFixturePlayerRepository = new OpponentFixturePlayerRepository();
        OpponentOtherFixtureDetailRepository opponentOtherFixtureDetailRepository = new OpponentOtherFixtureDetailRepository();

        ClubFixturePlayer clubFixturePlayer = new ClubFixturePlayer();

        // methods

        public ScorecardEditDataViewModel GetViewModelData(int fixtureId)
        {
            ScorecardEditDataViewModel scorecard = new ScorecardEditDataViewModel();
            scorecard.ScorecardFixture = fixtureRepository.GetFixture(fixtureId);
            scorecard.ScorecardHeaderDetail = scorecardHeaderRepository.GetScorecardHeader(scorecard.ScorecardFixture);
            scorecard.ClubPlayers = clubFixturePlayerRepository.GetClubBatsmen(scorecard.ScorecardFixture);
            
            scorecard.ClubOtherDetails = clubOtherFixtureDetailRepository.GetClubOtherFixtureDetail(scorecard.ScorecardFixture);
            scorecard.OpponentPlayers = opponentFixturePlayerRepository.GetOpponentBatsmen(scorecard.ScorecardFixture);
            scorecard.OpponentOtherDetails = opponentOtherFixtureDetailRepository.GetOpponentOtherFixtureDetail(scorecard.ScorecardFixture);
            scorecard.ClubDismissalId_SelectList = new SelectList(db.DismissalTypes, "dismissal_id", "type");
            scorecard.OppDismissalId_SelectList = new SelectList(db.DismissalTypes, "dismissal_id", "type");
            scorecard.ClubBatsman_SelectList = new SelectList(scorecard.ClubPlayers, "player_id", "Member.InitialAndLastName");
            scorecard.ClubBowler_SelectList = new SelectList(scorecard.ClubPlayers, "player_id", "Member.InitialAndLastName");                                          
            scorecard.OppBatsman_SelectList = new SelectList(scorecard.OpponentPlayers, "op_player_name", "op_player_name");
            scorecard.OppBowler_SelectList = new SelectList(scorecard.OpponentPlayers, "op_player_name", "op_player_name");

            return (scorecard);
        }


    }
}